/*
 * Driver declarations for Hardware Pulse Width Detector Peripheral Module
 *
 * Authors: Rohit Kulkarni
 * 			Raviraj Kokil
 *
 * Date : 21st Feb, 2015
 */



#ifndef HW_PWD_IP_H
#define HW_PWD_IP_H


/****************** Include Files ********************/
#include "xil_types.h"
#include "xil_io.h"
#include "xstatus.h"

#define HW_PWD_IP_S00_AXI_SLV_REG0_OFFSET 0
#define HW_PWD_IP_S00_AXI_SLV_REG1_OFFSET 4
#define HW_PWD_IP_S00_AXI_SLV_REG2_OFFSET 8
#define HW_PWD_IP_S00_AXI_SLV_REG3_OFFSET 12


/**************************** Type Definitions *****************************/
/**
 *
 * Write a value to a HW_PWD_IP register. A 32 bit write is performed.
 * If the component is implemented in a smaller width, only the least
 * significant data is written.
 *
 * @param   BaseAddress is the base address of the HW_PWD_IPdevice.
 * @param   RegOffset is the register offset from the base to write to.
 * @param   Data is the data written to the register.
 *
 * @return  None.
 *
 * @note
 * C-style signature:
 * 	void HW_PWD_IP_mWriteReg(u32 BaseAddress, unsigned RegOffset, u32 Data)
 *
 */
#define HW_PWD_IP_mWriteReg(BaseAddress, RegOffset, Data) \
  	Xil_Out32((BaseAddress) + (RegOffset), (u32)(Data))

/**
 *
 * Read a value from a HW_PWD_IP register. A 32 bit read is performed.
 * If the component is implemented in a smaller width, only the least
 * significant data is read from the register. The most significant data
 * will be read as 0.
 *
 * @param   BaseAddress is the base address of the HW_PWD_IP device.
 * @param   RegOffset is the register offset from the base to write to.
 *
 * @return  Data is the data from the register.
 *
 * @note
 * C-style signature:
 * 	u32 HW_PWD_IP_mReadReg(u32 BaseAddress, unsigned RegOffset)
 *
 */
#define HW_PWD_IP_mReadReg(BaseAddress, RegOffset) \
    Xil_In32((BaseAddress) + (RegOffset))

/************************** Function Prototypes ****************************/
/**
 *
 * Run a self-test on the driver/device. Note this may be a destructive test if
 * resets of the device are performed.
 *
 * If the hardware system is not built correctly, this function may never
 * return to the caller.
 *
 * @param   baseaddr_p is the base address of the HW_PWD_IP instance to be worked on.
 *
 * @return
 *
 *    - XST_SUCCESS   if all self-test code passed
 *    - XST_FAILURE   if any self-test code failed
 *
 * @note    Caching must be turned off for this function to work.
 * @note    Self test may fail if data memory and device are not on the same bus.
 *
 */
XStatus HW_PWD_IP_Reg_SelfTest(void * baseaddr_p);

/**
 * Function: XStatus HWPWD_initialize
 * Initializes the Hardware Pulse Width Detector Module
 * 
 * @param  : Takes a 32 bit base address and stores it for further use.
 *
 * @return
 *
 *    - XST_SUCCESS   if all self-test code passed
 *    - XST_FAILURE   if any self-test code failed
 *
 *  Note: This function should be called before any other since it takes the base address and stores
 *        it for further use.
 *
 */
XStatus HWPWD_initialize(u32);

/**
 * Function: Read_High_Count
 * Reads the high count from the 'high_count' register written by the hardware PWD.
 * 
 * @param  : No parameters
 *
 * @return : Returns the 32 bit high count value
 *
 */
 
u32 Read_High_Count();

/**
 * Function: Read_Low_Count
 * Reads the Low count from the 'Low_count' register written by the hardware PWD.
 * 
 * @param  : No parameters
 *
 * @return : Returns the 32 bit Low count value
 *
 */
u32 Read_Low_Count();

#endif // HW_PWD_IP_H
